All Questions
Tagged with numpynumpy-ndarray
2,869 questions
3votes
0answers
79views
numpy.load() seems to use double the memory of the array at peak
I thought numpy.load() writes directly into the array data memory. However, the results of the profiling functions (I profiled with memray and mprof) seems a bit strange to me... My array is 2GB big. ...
0votes
1answer
67views
Apparently weird condition on inclusion of endpoint in np.arange() [duplicate]
The numpy.arange function takes the three parameters: start, stop, step (positional args.) The default step is 1. Throughout my entire Numpy experience, the last element of the resultant array is not ...
1vote
1answer
47views
Pandas dataframe assign nested list not working
I'm trying to assign a dataframe cell with a nested list: df.loc['y','A'] = [[2]] However, the actual assigned value is [2]. It works expected for [2], [[[2]]], [[[[2]]]], but just not for [[2]] See ...
0votes
2answers
54views
Identify identical vectors as part of a multidimensional dot product
I am wanting to identify identical vectors after a dot product calc. The below works for a single dimension but not multi-dimensionally. Single Dimension a = np.array([0.8,0.5]) b = np.array([0.8,0.5])...
1vote
1answer
52views
unexpected results when using normal and advanced indexing with numpy
Consider the following: import numpy as np a = np.random.rand(123, 45, 3) print(a[:, :, [0, 1]].shape) # (123, 45, 2) print(a[:, 0, [0, 1]].shape) # (123, 2) print(a[0, :, [0, 1]].shape) # (2, 45)...
5votes
1answer
104views
Is there a Numpy method or function to split an array of uint64 into two arrays of uint32
Say I have an array as follows: arr = np.asarray([1, 2, 3, 4294967296, 100], dtype=np.uint64) I now want two arrays, one array with the lower 32 bits of every element, and one with the upper 32 bits ...
1vote
2answers
140views
'numpy.ndarray' object has no attribute 'groupby'
I am trying to apply target encoding to categorical features using the category_encoders.TargetEncoder in Python. However, I keep getting the following error: AttributeError: 'numpy.ndarray' object ...
10votes
1answer
607views
Arrays of size 0 in NumPy
I need to work with arrays that can have zeros in their shapes. However, I am encountering an issue. Here's an example: import numpy as np arr = np.array([[]]) assert arr.shape == (1,0) arr.reshape((...
2votes
1answer
124views
0-dimensional array problems with `numpy.vectorize`
numpy.vectorize conveniently converts a scalar function to vectorized functions that can be applied directly to arrays. However, when inputting a single value into the vectorized function, the output ...
1vote
0answers
47views
Python Numpy Crash without error or warning with exit code -1073740791 due to _multiarray_umath.cp312-win_amd64.pyd
Numpy library crash without console error or warning constantly In Python Console see notifications either Process finished with exit code -1073741819 (0xC0000005) or Process finished with exit code -...
0votes
1answer
106views
NumPy Stride Tricks: Is it possible to add the windows back into the original array size at the same location without for loops?
I'm currently trying to implement my own version of 2D Pooling (with channels included) in Python using only NumPy, but I've run into a bit of a roadblock with vectorizing the backpropagation process. ...
-1votes
1answer
41views
Sort columns of numpy unitary matrix such that highest element of each column is on the diagonal
Take a unitary matrix U. I want to swap the columns such that the largest element of each column (in absolute value) is on the diagonal (modulo ties). What is the best way to do this in numpy?
0votes
1answer
50views
How to get row numbers of maximum elements in a 2D Numpy array? [duplicate]
I have a 2D array a given by: a = np.array([[2, 3, 1, 9], [0, 5, 4, 7], [2, 4, 6, 8]]) [[2 3 1 9] [0 5 4 7] [2 4 6 8]] I would like to get row numbers of maximum elements column-wise, i.e. given ...
0votes
1answer
71views
Removing rows from numpy 3D array based on last element
What I'm trying to do is essentially removing all rows h,s in a 3D numpy array a if a[h,s,v] = some value for all v More specifically, I have a loaded image from cv2 which contains some transparent ...
1vote
2answers
42views
Counting the hashtags in a collection of tweets: two methods with inconsistent results
I'm playing around with a numpy dataframe containing two columns: 'tweet_text' and 'cyberbullying_type'. It was created through this dataset as follows: df = pd.read_csv('data/cyberbullying_tweets.csv'...